{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "模型准确率: 1.00\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Users\\Gaona\\.conda\\envs\\pytorchgpu\\lib\\site-packages\\xgboost\\core.py:158: UserWarning: [15:48:29] WARNING: C:\\buildkite-agent\\builds\\buildkite-windows-cpu-autoscaling-group-i-0c55ff5f71b100e98-1\\xgboost\\xgboost-ci-windows\\src\\learner.cc:740: \n",
      "Parameters: { \"use_label_encoder\" } are not used.\n",
      "\n",
      "  warnings.warn(smsg, UserWarning)\n"
     ]
    }
   ],
   "source": [
    "import numpy as np  \n",
    "import pandas as pd  \n",
    "from sklearn.datasets import load_iris  \n",
    "from sklearn.model_selection import train_test_split  \n",
    "from xgboost import XGBClassifier  \n",
    "from sklearn.metrics import accuracy_score  \n",
    "\n",
    "# 1. 加载数据集  \n",
    "iris = load_iris()  \n",
    "X = iris.data  \n",
    "y = iris.target  \n",
    "\n",
    "# 2. 拆分数据集  \n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)  \n",
    "\n",
    "# 3. 创建 XGBoost 分类器  \n",
    "model = XGBClassifier(use_label_encoder=False, eval_metric='mlogloss')  \n",
    "\n",
    "# 4. 训练模型  \n",
    "model.fit(X_train, y_train)  \n",
    "\n",
    "# 5. 预测  \n",
    "y_pred = model.predict(X_test)  \n",
    "\n",
    "# 6. 评估模型  \n",
    "accuracy = accuracy_score(y_test, y_pred)  \n",
    "print(f'模型准确率: {accuracy:.2f}')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "pytorchgpu",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.20"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
